<?php

namespace app\shopapi\hook;


use app\admin\model\Config;

use Curl\Curl;

class Sms
{
    public function run($sms)
    {

        require_once ROOT_PATH.'vendor/php-curl-class/php-curl-class/src/Curl/Curl.php';

        $config = \app\admin\model\shop\Config::get(1);
        $name = $config->sitename;

        if ($sms->event=='mobilelogin'){
            $content = "【{$name}】您的登录验证码为{$sms->code},请勿泄露他人,若非本人操作,请忽略此信息";
        } elseif ($sms->event=='register'){
            $content = "【{$name}】您的注册验证码为{$sms->code},请勿泄露他人,若非本人操作,请忽略此信息";
        } elseif ($sms->event=='changemobile'){
            $content = "【{$name}】您的手机验证码为{$sms->code},请勿泄露他人,若非本人操作,请忽略此信息";
        }  elseif ($sms->event=='createadmin'){
            $content = "【{$name}】您的手机验证码为{$sms->code},请勿泄露他人,若非本人操作,请忽略此信息";
        } elseif ($sms->event=='sendcontract'){
            $request = \think\Request::instance();
            $notify_url = $request->root(true) . '/shopapi/auth/contracturl/code/';
            $content = "【{$name}】尊敬的客户,哇哇来购正在代您申请开通收款服务，请进行协议签署,".$notify_url.$sms->short_url;
        }
        $api = "http://182.92.174.25:8513/sms/Api/Send.do";
        $data = [
            'SpCode'=>'1801',//企业编号
            'LoginName'=>'DOUXING',//用户名称JHC1
            'Password'=>'dx@666888D',//用户密码
            'MessageContent'=>$content,//短信内容,最大700个字符
            'UserNumber'=>$sms->mobile,//手机号码
        ];

        $curl = new Curl();
        $curl->setOpt(CURLOPT_SSL_VERIFYPEER, false);
        $curl->post($api,$data);
        $res = $curl->response;

        $result = strpos($res, 'result=0');
        return true;

    }
}